"""


"""

import os
from pathlib import Path

# 
PROJECT_NAME = ""
PROJECT_VERSION = "1.0.0"
PROJECT_DESCRIPTION = "OpenAI Whisper"

# 
BASE_DIR = Path(__file__).parent
SRC_DIR = BASE_DIR / "src"
TEMP_DIR = BASE_DIR / "temp"
OUTPUT_DIR = BASE_DIR / "output"

# 
TEMP_DIR.mkdir(exist_ok=True)
OUTPUT_DIR.mkdir(exist_ok=True)

# Whisper
WHISPER_MODELS = {
    'tiny': {'size': '39MB', 'speed': '', 'accuracy': '', 'vram': '~1GB'},
    'base': {'size': '74MB', 'speed': '', 'accuracy': '', 'vram': '~1GB'},
    'small': {'size': '244MB', 'speed': '', 'accuracy': '', 'vram': '~2GB'},
    'medium': {'size': '769MB', 'speed': '', 'accuracy': '', 'vram': '~5GB'},
    'large': {'size': '1550MB', 'speed': '', 'accuracy': '', 'vram': '~10GB'},
    'large-v2': {'size': '1550MB', 'speed': '', 'accuracy': '', 'vram': '~10GB'},
    'large-v3': {'size': '1550MB', 'speed': '', 'accuracy': '', 'vram': '~10GB'}
}

# 
DEFAULT_SETTINGS = {
    'whisper_model': 'base',
    'language': 'auto',
    'output_format': 'txt',
    'chunk_duration': 600,  # 
    'sample_rate': 16000,
    'device': 'auto',  # auto, cpu, cuda
    'verbose': True,
    'cleanup_temp': True
}

# 
SUPPORTED_VIDEO_FORMATS = [
    '.mp4', '.avi', '.mkv', '.mov', '.wmv', 
    '.flv', '.webm', '.m4v', '.3gp', '.ogv'
]

SUPPORTED_AUDIO_FORMATS = [
    '.mp3', '.wav', '.flac', '.aac', '.ogg', 
    '.m4a', '.wma', '.opus'
]

# 
SUPPORTED_LANGUAGES = {
    'auto': '',
    'zh': '',
    'en': '',
    'ja': '',
    'ko': '',
    'fr': '',
    'de': '',
    'es': '',
    'ru': '',
    'it': '',
    'pt': '',
    'ar': '',
    'hi': '',
    'th': '',
    'vi': ''
}

# 
OUTPUT_FORMATS = {
    'txt': '',
    'srt': 'SRT',
    'vtt': 'WebVTT',
    'json': 'JSON',
    'tsv': 'TSV'
}

# Web
WEB_CONFIG = {
    'title': PROJECT_NAME,
    'page_icon': '',
    'layout': 'wide',
    'initial_sidebar_state': 'expanded',
    'max_upload_size': 500,  # MB
    'allowed_extensions': SUPPORTED_VIDEO_FORMATS + SUPPORTED_AUDIO_FORMATS
}

# 
DESKTOP_CONFIG = {
    'window_title': PROJECT_NAME,
    'window_size': (1200, 800),
    'min_window_size': (800, 600),
    'theme': 'Material',
    'font_size_multiplier': 1.2,  # 
    # 
    'fonts_by_os': {
        'darwin': {  # macOS
            'primary': 'PingFang SC',
            'fallbacks': ['Heiti SC', 'STHeiti', 'Arial Unicode MS', 'Helvetica Neue'],
            'font_paths': [
                '/System/Library/Fonts/PingFang.ttc',
                '/System/Library/Fonts/STHeiti Medium.ttc',
                '/System/Library/Fonts/Helvetica.ttc'
            ]
        },
        'win32': {  # Windows
            'primary': 'Microsoft YaHei',
            'fallbacks': ['SimHei', 'SimSun', 'NSimSun', 'Arial Unicode MS'],
            'font_paths': [
                'C:/Windows/Fonts/msyh.ttc',  # 
                'C:/Windows/Fonts/simhei.ttf',  # 
                'C:/Windows/Fonts/simsun.ttc'   # 
            ]
        },
        'linux': {  # Linux
            'primary': 'Noto Sans CJK SC',
            'fallbacks': ['WenQuanYi Micro Hei', 'DejaVu Sans', 'Arial Unicode MS'],
            'font_paths': [
                '/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc',
                '/usr/share/fonts/truetype/wqy/wqy-microhei.ttc',
                '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf'
            ]
        }
    }
}

# 
LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
        },
        'detailed': {
            'format': '%(asctime)s [%(levelname)s] %(name)s:%(lineno)d: %(message)s'
        }
    },
    'handlers': {
        'default': {
            'level': 'INFO',
            'formatter': 'standard',
            'class': 'logging.StreamHandler',
        },
        'file': {
            'level': 'DEBUG',
            'formatter': 'detailed',
            'class': 'logging.FileHandler',
            'filename': 'app.log',
            'mode': 'a',
        }
    },
    'loggers': {
        '': {
            'handlers': ['default', 'file'],
            'level': 'DEBUG',
            'propagate': False
        }
    }
}

# 
def get_env_var(name: str, default=None):
    """"""
    return os.getenv(name, default)

# CUDA
CUDA_AVAILABLE = False
try:
    import torch
    CUDA_AVAILABLE = torch.cuda.is_available()
except ImportError:
    pass

# 
def get_device():
    """"""
    if DEFAULT_SETTINGS['device'] == 'auto':
        return 'cuda' if CUDA_AVAILABLE else 'cpu'
    return DEFAULT_SETTINGS['device']